<template>
  <div class="user">
    <div class="head">
      <van-image round width="64" height="64" :src="userinfo.photo" />
      <h2 class="name">
        {{ userinfo.name }}
        <br />
        <van-tag type="primary" color="#fff" text-color="#3296fa">{{
          userinfo.birthday
        }}</van-tag>
      </h2>
    </div>
    <!-- 操作导航 -->
    <van-row class="user-nav">
      <van-col span="8">
        <van-icon name="newspaper-o" color="#7af" />我的作品
      </van-col>
      <van-col span="8">
        <van-icon name="star-o" color="#f00" />我的收藏
      </van-col>
      <van-col span="8">
        <van-icon name="tosend" color="#fa0" />阅读历史
      </van-col>
    </van-row>
    <!-- 表格页 -->
    <van-cell-group>
      <van-cell is-link title="编辑资料" icon="edit" @click="$router.push({path:'/edit'})"/>
      <van-cell is-link title="小智同学" icon="chat-o" />
      <van-cell is-link title="系统设置" icon="setting-o" />
      <van-cell is-link title="退出登录" icon="warning-o" @click="signout" />
    </van-cell-group>
  </div>
</template>

<script>

import { userinformation } from "./user";
import { removetoKen } from "../../utils/token";
export default {
  name: "user",
  data() {
    return {
      userinfo: {},
    };
  },
  async created() {
    let res = await userinformation();
    this.userinfo = res.data.data;
    this.$store.commit('setuserinfo',res.data.data)
  },
  methods: {
    signout() {
      this.$dialog.confirm({
        title: "确定退出",
        message: "好吧，我也不知道说啥",
      }).then(()=>{
        //退出删除token
        removetoKen()
        //清除用户信息
        this.userinfo ={}
        //跳转登录页
        this.$router.push({path:'/login'})
      })
    },
  },
};
</script>

<style lang="less">
.user {
  /* 头部 */
  .head {
    height: 100px;
    background-image: linear-gradient(to right bottom, green, yellow, red);
    display: flex;
    align-items: center;
    padding-left: 15px;
    .name {
      font-size: 18px;
      margin-left: 15px;
      color: white;
      font-weight: normal;
    }
  }

  /* 操作导航 */
  .user-nav {
    padding: 15px 0;
    font-size: 12px;
    text-align: center;
    background-color: #fff;
    .van-icon {
      display: block;
      font-size: 24px;
      padding-bottom: 5px;
    }
  }
}
</style>